package me.lwn.auth.domain;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.springframework.util.StringUtils;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.time.Instant;
import java.util.Set;

@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@Table(name = "oauth2_registered_client")
public class Client {
    @Id
    private String id;
    private String clientId;
    private Instant clientIdIssuedAt;
    private String clientSecret;
    private Instant clientSecretExpiresAt;
    private String clientName;
    private String clientAuthenticationMethods;
    private String authorizationGrantTypes;
    private String redirectUris;
    private String scopes;

    public Set<String> getClientAuthenticationMethods() {
        return StringUtils.commaDelimitedListToSet(clientAuthenticationMethods);
    }

    public Set<String> getAuthorizationGrantTypes() {
        return StringUtils.commaDelimitedListToSet(authorizationGrantTypes);
    }

    public Set<String> getRedirectUris() {
        return StringUtils.commaDelimitedListToSet(redirectUris);
    }

    public Set<String> getScopes() {
        return StringUtils.commaDelimitedListToSet(scopes);
    }
}